home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / reportplus / source / f4.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  17.0 KB  |  549 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <workbench/icon.h>
  6. #include <workbench/workbench.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include "rp.h" // before icon protos
  10.  
  11. #include <clib/alib_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <pragmas/icon_pragmas.h>
  17. #include <reaction/reaction.h>
  18. #include <gadgets/chooser.h>
  19. #include <pragmas/chooser_pragmas.h>
  20. #include <gadgets/string.h>
  21. #include <pragmas/string_pragmas.h>
  22. #include <gadgets/checkbox.h>
  23. #include <pragmas/checkbox_pragmas.h>
  24. #include <gadgets/layout.h>
  25. #include <pragmas/layout_pragmas.h>
  26. #include <gadgets/button.h>
  27. #include <pragmas/button_pragmas.h>
  28. #include <images/label.h>
  29. #include <pragmas/label_pragmas.h>
  30. #include <proto/label.h>
  31. #include <classes/window.h>
  32. #include <pragmas/window_pragmas.h>
  33.  
  34. #include <stdlib.h>
  35. #include <string.h>
  36.  
  37. AGLOBAL ABOOL              quit              = FALSE;
  38. AGLOBAL struct Gadget*     icon_gadgets[GIDS_4 + 1];
  39. AGLOBAL struct IconStruct  icon =
  40. {   TRUE, FALSE,
  41.     WBDRAWER, ""
  42. };
  43.  
  44. // from rp.c
  45. IMPORT Object*             WinObject[FUNCTIONS + 1];
  46. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  47. IMPORT SBYTE               page;
  48. IMPORT TEXT                asldir[PATHNAMEFIELD + 1];
  49. IMPORT ULONG               signal;
  50. IMPORT struct Window*      MainWindowPtr;
  51. IMPORT struct Screen*      ScreenPtr;
  52. IMPORT struct SharedStruct shared;
  53. IMPORT struct Library     *ButtonBase,
  54.                           *CheckBoxBase,
  55.                           *ChooserBase,
  56.                           *IconBase,
  57.                           *LabelBase,
  58.                           *LayoutBase,
  59.                           *StringBase,
  60.                           *WindowBase;
  61. IMPORT struct Menu*        MenuPtr;
  62. IMPORT ABOOL               done;
  63. IMPORT TEXT                aslresult[PATHNAMEFIELD + 1];
  64.  
  65. #define ICONOPTIONS        8
  66.  
  67. MODULE ABOOL               stop;
  68. MODULE STRPTR IconOptions[ICONOPTIONS] =
  69. {   "Disk",
  70.     "Drawer",
  71.     "Tool",
  72.     "Project",
  73.     "Trashcan",
  74.     "Device",
  75.     "Kickstart",
  76.     "AppIcon"
  77. };
  78. /* icon.type is the same as the values used by the system. So, the
  79. value used by the gadget is one less than the actual value. */
  80.  
  81. AGLOBAL void icon1(void)
  82. {   ULONG               i;
  83.     struct List         ChooserList;
  84.     struct ChooserNode *ChooserNodePtr[7 + 1];
  85.     struct Hook         Hook4Struct;
  86.  
  87.     icon.pathname[0] = 0;
  88.  
  89.     NewList(&ChooserList);
  90.     for (i = 0; i <= 7; i++)
  91.     {   if (!(ChooserNodePtr[i] = (struct ChooserNode *) AllocChooserNode(CNA_Text, IconOptions[i], TAG_DONE)))
  92.         {   rq("Can't allocate chooser node!");
  93.         }
  94.         AddTail(&ChooserList, (struct Node *) ChooserNodePtr[i]);
  95.     } // automatically freed by ReAction at DisposeObject() time
  96.  
  97.     InitHook(&Hook4Struct, Hook4Func, NULL);
  98.  
  99.     /* Create the window object. */
  100.     lockscreen();
  101.     if (!(WinObject[4] =          NewObject(WINDOW_GetClass(), NULL,
  102.     // window
  103.     WA_PubScreen,                 ScreenPtr,
  104.     WA_ScreenTitle,               "Report+",
  105.     WA_Title,                     "Report+: Icon Processor",
  106.     WA_Activate,                  TRUE,
  107.     WA_DepthGadget,               TRUE,
  108.     WA_DragBar,                   TRUE,
  109.     WA_CloseGadget,               TRUE,
  110.     WA_SizeGadget,                TRUE,
  111.     WA_IDCMP,                     IDCMP_RAWKEY,
  112.     WINDOW_IDCMPHook,             &Hook4Struct,
  113.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  114.     WINDOW_MenuStrip,             MenuPtr,
  115.     WINDOW_Position,              WPOS_CENTERSCREEN,
  116.     WINDOW_ParentGroup,           icon_gadgets[GID_4_LY1] =
  117.                                   NewObject(LAYOUT_GetClass(), NULL,
  118.         // root-layout
  119.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  120.         LAYOUT_SpaceOuter,        TRUE,
  121.         LAYOUT_DeferLayout,       TRUE,
  122.         LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  123.             // layout
  124.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  125.             LAYOUT_VertAlignment, LALIGN_CENTER,
  126.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  127.             LAYOUT_BevelStyle,    BVS_NONE,
  128.             LAYOUT_AddChild,      icon_gadgets[GID_4_CB1] =
  129.                                   NewObject(CHECKBOX_GetClass(), NULL,
  130.                 GA_ID,                GID_4_CB1,
  131.                 GA_RelVerify,         TRUE,
  132.                 GA_Text,              "_Optimize colours?",
  133.                 GA_Selected,          (BOOL) icon.optimize,
  134.             TAG_END),
  135.             CHILD_WeightedHeight,     0,
  136.             LAYOUT_AddImage,          NewObject
  137.             (   LABEL_GetClass(),     NULL,
  138.                 LABEL_Text,           "",
  139.                 TAG_END
  140.             ),
  141.             CHILD_WeightedWidth,      100,
  142.             LAYOUT_AddImage,
  143.             NewObject
  144.             (   LABEL_GetClass(),     NULL,
  145.                 LABEL_Text,           "_Type:",
  146.                 LABEL_Justification,  LJ_LEFT,
  147.             TAG_END),
  148.             CHILD_WeightedWidth,      0,
  149.             LAYOUT_AddChild,          icon_gadgets[GID_4_CH1] =
  150.             NewObject
  151.             (   CHOOSER_GetClass(),   NULL,
  152.                 GA_ID,                GID_4_CH1,
  153.                 GA_RelVerify,         TRUE,
  154.                 CHOOSER_PopUp,        TRUE,
  155.                 CHOOSER_Labels,       &ChooserList,
  156.                 CHOOSER_Selected,     (WORD) (icon.type - 1),
  157.             TAG_END),
  158.             CHILD_WeightedWidth,      0,
  159.         TAG_END), 
  160.         CHILD_WeightedHeight,         0,
  161.         LAYOUT_AddChild,              icon_gadgets[GID_4_CB2] =
  162.                                       NewObject(CHECKBOX_GetClass(), NULL,
  163.                 // checkbox
  164.                 GA_ID,                GID_4_CB2,
  165.                 GA_RelVerify,         TRUE,
  166.                 GA_Text,              "Preserve p_lanar data?",
  167.                 GA_Selected,          (BOOL) icon.planar,
  168.                 TAG_END),
  169.             CHILD_WeightedHeight,     0,
  170.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  171.                 // layout
  172.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  173.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  174.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  175.                 LAYOUT_BevelStyle,    BVS_NONE,
  176.                 LAYOUT_AddImage,      NewObject(LABEL_GetClass(), NULL,
  177.                     // label
  178.                     LABEL_Text,       "_Pathname(s):",
  179.                     LABEL_Justification,LJ_LEFT,
  180.                     TAG_END),
  181.                 LAYOUT_AddChild,      icon_gadgets[GID_4_ST1] =
  182.                                       NewObject(STRING_GetClass(), NULL,
  183.                     // string        
  184.                     GA_ID,            GID_4_ST1,
  185.                     GA_RelVerify,     TRUE,
  186.                     STRINGA_TextVal,  icon.pathname,
  187.                     STRINGA_MinVisible,20,
  188.                     TAG_END),
  189.                 LAYOUT_AddChild,      icon_gadgets[GID_4_BU1] =
  190.                                       NewObject(NULL, "button.gadget",
  191.                     // button
  192.                     GA_ID,            GID_4_BU1,
  193.                     GA_RelVerify,     TRUE,
  194.                     BUTTON_AutoButton,BAG_POPFILE,
  195.                     TAG_END),
  196.                 CHILD_WeightedWidth,  0,
  197.                 TAG_END),
  198.             CHILD_WeightedHeight,     0,
  199.             LAYOUT_AddChild,          icon_gadgets[GID_4_ST2] =
  200.                                       NewObject(STRING_GetClass(), NULL,
  201.                 // string        
  202.                 GA_ReadOnly,          TRUE,
  203.                 GA_ID,                GID_4_ST2,
  204.                 STRINGA_TextVal,      "Ready.",
  205.                 TAG_END),
  206.             CHILD_WeightedHeight,     0,
  207.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  208.                 // layout
  209.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  210.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  211.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  212.                 LAYOUT_BevelStyle,    BVS_NONE,
  213.                 LAYOUT_AddChild,      icon_gadgets[GID_4_BU3] =
  214.                                       NewObject(NULL, "button.gadget",
  215.                     // button
  216.                     GA_ID,            GID_4_BU3,
  217.                     GA_RelVerify,     TRUE,
  218.                     GA_Text,          "Pro_cess",
  219.                 TAG_END),
  220.                 CHILD_WeightedWidth,  50,
  221.                 LAYOUT_AddChild,      icon_gadgets[GID_4_BU4] =
  222.                                       NewObject(NULL, "button.gadget",
  223.                     // button
  224.                     GA_ID,            GID_4_BU4,
  225.                     GA_RelVerify,     TRUE,
  226.                     GA_Text,          "Stop",
  227.                     GA_Disabled,      TRUE,
  228.                     TAG_END),
  229.                 CHILD_WeightedWidth,  50,
  230.                 TAG_END),
  231.             CHILD_WeightedHeight,     0,
  232.             TAG_END),
  233.     TAG_END)
  234.     ))
  235.     {   rq("Can't create ReAction objects!");
  236.     }
  237.     unlockscreen();
  238.     openwindow();
  239.     ActivateLayoutGadget(icon_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_4_ST1]);
  240.     loop();
  241.     closewindow();
  242.     if (quit)
  243.     {   cleanexit(EXIT_SUCCESS);
  244. }   }
  245.  
  246. AGLOBAL void icon_do(void)
  247. {   ABOOL  anyfound;
  248.     STRPTR stringptr;
  249.  
  250.     if (!(GetAttr
  251.     (   CHOOSER_Selected, icon_gadgets[GID_4_CH1], (ULONG *) &(icon.type)
  252.     )))
  253.     {   rq("Unsupported inquiry!"); // should never happen
  254.     }
  255.     icon.type++;
  256.  
  257.     if (!(GetAttr
  258.     (   STRINGA_TextVal, icon_gadgets[GID_4_ST1], (ULONG *) &stringptr
  259.     )))
  260.     {   rq("Unsupported inquiry!"); // should never happen
  261.     }
  262.     strcpy(icon.pathname, stringptr);
  263.  
  264.     if (!(GetAttr
  265.     (   GA_Selected, icon_gadgets[GID_4_CB1], (ULONG *) &(icon.optimize)
  266.     )))
  267.     {   rq("Unsupported inquiry!"); // should never happen
  268.     }
  269.     if (!(GetAttr
  270.     (   GA_Selected, icon_gadgets[GID_4_CB2], (ULONG *) &(icon.planar)
  271.     )))
  272.     {   rq("Unsupported inquiry!"); // should never happen
  273.     }
  274.  
  275.     SetGadgetAttrs
  276.     (   icon_gadgets[GID_4_CH1], MainWindowPtr, NULL,
  277.         GA_Disabled, TRUE,
  278.         TAG_END
  279.     );
  280.     SetGadgetAttrs
  281.     (   icon_gadgets[GID_4_CB1], MainWindowPtr, NULL,
  282.         GA_Disabled, TRUE,
  283.         TAG_END
  284.     );
  285.     SetGadgetAttrs
  286.     (   icon_gadgets[GID_4_CB2], MainWindowPtr, NULL,
  287.         GA_Disabled, TRUE,
  288.         TAG_END
  289.     );
  290.     SetGadgetAttrs
  291.     (   icon_gadgets[GID_4_ST1], MainWindowPtr, NULL,
  292.         GA_Disabled, TRUE,
  293.         TAG_END
  294.     );
  295.     SetGadgetAttrs
  296.     (   icon_gadgets[GID_4_BU1], MainWindowPtr, NULL,
  297.         GA_Disabled, TRUE,
  298.         TAG_END
  299.     );
  300.     SetGadgetAttrs
  301.     (   icon_gadgets[GID_4_BU3], MainWindowPtr, NULL,
  302.         GA_Disabled, TRUE,
  303.         TAG_END
  304.     );
  305.     SetGadgetAttrs
  306.     (   icon_gadgets[GID_4_BU4], MainWindowPtr, NULL,
  307.         GA_Disabled, FALSE,
  308.         TAG_END
  309.     );
  310.     SetAttrs
  311.     (   WinObject[4],
  312.         WA_BusyPointer, TRUE,
  313.         TAG_END
  314.     );
  315.                           
  316.     strcpy(shared.pathname, icon.pathname);
  317.     anyfound = convert(TRUE);
  318.     strcpy(icon.pathname, shared.pathname);
  319.  
  320.     if (!stop)
  321.     {   if (anyfound)
  322.         {   SetGadgetAttrs
  323.             (   icon_gadgets[GID_4_ST2], MainWindowPtr, NULL,
  324.                 STRINGA_TextVal, "All done.",
  325.             TAG_END);
  326.         } else
  327.         {   SetGadgetAttrs
  328.             (   icon_gadgets[GID_4_ST2], MainWindowPtr, NULL,
  329.                 STRINGA_TextVal, "No matches!",
  330.             TAG_END);
  331.     }   }
  332.     SetAttrs
  333.     (   WinObject[4],
  334.         WA_BusyPointer, FALSE,
  335.         TAG_END
  336.     );
  337.     SetGadgetAttrs
  338.     (   icon_gadgets[GID_4_CH1], MainWindowPtr, NULL,
  339.         GA_Disabled, FALSE,
  340.         TAG_END
  341.     );
  342.     SetGadgetAttrs
  343.     (   icon_gadgets[GID_4_CB1], MainWindowPtr, NULL,
  344.         GA_Disabled, FALSE,
  345.         TAG_END
  346.     );
  347.     SetGadgetAttrs
  348.     (   icon_gadgets[GID_4_CB2], MainWindowPtr, NULL,
  349.         GA_Disabled, FALSE,
  350.         TAG_END
  351.     );
  352.     SetGadgetAttrs
  353.     (   icon_gadgets[GID_4_ST1], MainWindowPtr, NULL,
  354.         GA_Disabled, FALSE,
  355.         TAG_END
  356.     );
  357.     SetGadgetAttrs
  358.     (   icon_gadgets[GID_4_BU1], MainWindowPtr, NULL,
  359.         GA_Disabled, FALSE,
  360.         TAG_END
  361.     );
  362.     SetGadgetAttrs
  363.     (   icon_gadgets[GID_4_BU3], MainWindowPtr, NULL,
  364.         GA_Disabled, FALSE,
  365.         TAG_END
  366.     );
  367.     SetGadgetAttrs
  368.     (   icon_gadgets[GID_4_BU4], MainWindowPtr, NULL,
  369.         GA_Disabled, TRUE,
  370.         TAG_END
  371.     );
  372. }
  373.  
  374. AGLOBAL void iconconvert(ABOOL gui)
  375. {   TEXT               saystring[LONGFIELD + 1];
  376.     ULONG              length = strlen(shared.thisfile);
  377.     struct DiskObject* IconPtr;
  378.  
  379.     if (length <= 5) // in case we get passed an empty string
  380.     {   return;
  381.     }
  382.     if (!stricmp(&(shared.thisfile[length - 5]), ".info"))
  383.     {   shared.thisfile[length - 5] = 0;
  384.     }
  385.    
  386.     strcpy(saystring, "Processing ");
  387.     strcat(saystring, shared.thisfile);
  388.     strcat(saystring, ".info...");
  389.     if (gui)
  390.     {   SetGadgetAttrs
  391.         (   icon_gadgets[GID_4_ST2], MainWindowPtr, NULL,
  392.             STRINGA_TextVal, saystring,
  393.             TAG_END
  394.         );
  395.     } else
  396.     {   Printf("%s", saystring);
  397.         Flush(Output());
  398.         saystring[0] = 0;
  399.     }
  400.  
  401.     if (IconPtr = GetIconTags(shared.thisfile, TAG_DONE))
  402.     {   IconPtr->do_Type = (UWORD) icon.type;
  403.         if (PutIconTags(shared.thisfile, IconPtr,
  404.             ICONPUTA_NotifyWorkbench,     TRUE,
  405.             ICONPUTA_DropPlanarIconImage, (BOOL) !icon.planar,
  406.             ICONPUTA_OptimizeImageSpace,  (BOOL) icon.optimize,
  407.             TAG_DONE
  408.         ))
  409.         {   strcat(saystring, "done.");
  410.         } else strcat(saystring, "failed to write!");
  411.         FreeDiskObject(IconPtr);
  412.     } else strcat(saystring, "failed to read!");
  413.  
  414.     if (gui)
  415.     {   SetGadgetAttrs
  416.         (   icon_gadgets[GID_4_ST2], MainWindowPtr, NULL,
  417.             STRINGA_TextVal, saystring,
  418.             TAG_END
  419.         );
  420.     } else
  421.     {   Printf("%s\n", saystring);
  422.     }
  423.  
  424.     checkabort(gui);
  425. }
  426.  
  427. AGLOBAL void icon_loop(ULONG gid)
  428. {   STRPTR stringptr;
  429.  
  430.     switch (gid)
  431.     {
  432.     case GID_4_CH1:
  433.         if (!(GetAttr
  434.         (   CHOOSER_Selected, icon_gadgets[GID_4_CH1], (ULONG *) &(icon.type)
  435.         )))
  436.         {   rq("Unsupported inquiry!"); // should never happen
  437.         }
  438.         icon.type++;
  439.     break;
  440.     case GID_4_ST1:
  441.         if (!(GetAttr
  442.         (   STRINGA_TextVal, icon_gadgets[GID_4_ST1], (ULONG *) &stringptr
  443.         )))
  444.         {   rq("Unsupported inquiry!"); // should never happen
  445.         }
  446.         strcpy(icon.pathname, stringptr);
  447.     break;
  448.     case GID_4_BU1:
  449.         strcpy(shared.pathname, icon.pathname);
  450.         multiasl("#?.info");
  451.         strcpy(icon.pathname, shared.pathname);
  452.         SetGadgetAttrs
  453.         (   icon_gadgets[GID_4_ST1], MainWindowPtr, NULL,
  454.             STRINGA_TextVal, icon.pathname,
  455.             TAG_END
  456.         );
  457.     break;
  458.     case GID_4_BU3:
  459.         icon_do();
  460.     break;
  461.     case GID_4_CB1:
  462.         if (!(GetAttr
  463.         (   GA_Selected, icon_gadgets[GID_4_CB1], (ULONG *) &(icon.optimize)
  464.         )))
  465.         {   rq("Unsupported inquiry!"); // should never happen
  466.         }
  467.     break;
  468.     case GID_4_CB2:
  469.         if (!(GetAttr
  470.         (   GA_Selected, icon_gadgets[GID_4_CB2], (ULONG *) &(icon.planar)
  471.         )))
  472.         {   rq("Unsupported inquiry!"); // should never happen
  473.         }
  474.     break;
  475.     default:
  476.     break;
  477. }   }
  478.  
  479. AGLOBAL ULONG Hook4Func(struct Hook *h, VOID *o, VOID *msg)
  480. {   /* "When the hook is called, the data argument points to the 
  481.     window object and message argument to the IntuiMessage." */
  482.  
  483.     UWORD code, qual;
  484.  
  485.     geta4(); // wait till here before doing anything
  486.  
  487.     code = ((struct IntuiMessage *) msg)->Code;
  488.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  489.  
  490.     switch(code)
  491.     {
  492.     case SCAN_HELP:
  493.         helpabout();
  494.     break;
  495.     case SCAN_ESCAPE:
  496.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  497.         {   cleanexit(EXIT_SUCCESS);
  498.         } else page = 0;
  499.     break;
  500.     case SCAN_P:
  501.         ActivateLayoutGadget(icon_gadgets[GID_4_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_4_ST1]);
  502.     break;
  503.     case SCAN_T:
  504.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  505.         {   if (icon.type == 1)
  506.             {   icon.type = ICONOPTIONS;
  507.             } else icon.type--;
  508.         } else
  509.         {   if (icon.type == ICONOPTIONS)
  510.             {   icon.type = 1;
  511.             } else icon.type++;
  512.         }
  513.  
  514.         SetGadgetAttrs
  515.         (   icon_gadgets[GID_4_CH1], MainWindowPtr, NULL,
  516.             CHOOSER_Selected, icon.type - 1,
  517.             TAG_END
  518.         );
  519.     break;
  520.     case SCAN_PERIOD:
  521.         strcpy(shared.pathname, icon.pathname);
  522.         multiasl("#?.info");
  523.         strcpy(icon.pathname, shared.pathname);
  524.         SetGadgetAttrs
  525.         (   icon_gadgets[GID_4_ST1], MainWindowPtr, NULL,
  526.             STRINGA_TextVal, icon.pathname,
  527.             TAG_END
  528.         );
  529.     break;
  530.     default:
  531.     break;
  532.     }
  533.  
  534.     return(1);
  535. }
  536.  
  537. AGLOBAL void icon_die(void)
  538. {   IOBuffer[16] = (UBYTE) icon.type;
  539.     IOBuffer[17] = (UBYTE) icon.optimize;
  540.     IOBuffer[18] = (UBYTE) icon.planar;
  541. }
  542.  
  543. AGLOBAL void icon_config(void)
  544. {   icon.type     = (ULONG) IOBuffer[16];
  545.     icon.optimize = (ULONG) IOBuffer[17];
  546.     icon.planar   = (ULONG) IOBuffer[18];
  547. }
  548.  
  549.